<?php
class Core_Data_Logger {
	
	private $database;
	
	public function __construct(){
		$this->database = new Core_Driver_MysqlImproved;
	}
	
	public function saveData($username, $accessLevel){
		
		$requestUri = $_SERVER['REQUEST_URI'];
		$remoteAddress = $_SERVER['REMOTE_ADDR'];
		$remoteBrowser = $_SERVER['HTTP_USER_AGENT'];
		$remoteHost = gethostbyaddr($remoteAddress);
		$requestReferer = $_SERVER['HTTP_REFERER'];
		
		$this->database->connect();
		
		$username = $this->database->escape($username);
		$accessLevel = $this->database->escape($accessLevel);
		$requestUri = $this->database->escape($requestUri);
		$remoteAddress = $this->database->escape($remoteAddress);
		$remoteHost = $this->database->escape($remoteHost);
		$remoteBrowser = $this->database->escape($remoteBrowser);
		$requestReferer = $this->database->escape($requestReferer);
		
		$this->database->prepare(
			"
				insert into logger(request_referer, client_ip, client_host, client_data, client_name, client_access_level, request_url) values('$requestReferer', '$remoteAddress', '$remoteHost', '$remoteBrowser', '$username', '$accessLevel', '$requestUri');
				"
		);
		$this->database->query();
		$this->database->dataOperations();
		
	}
	
}